#include "gpio.h"
#include <iostream>
#include "esm6800_drivers.h"
#include <unistd.h>
#include "can_app.h"
#include "Serial.h"
#include "string.h"

#include "rs485.h"
#include <sys/ipc.h>
#include <sys/msg.h>

using namespace std;

int main(int argc, char * argv[])
{ 
    int ret = 0;  

    CRs485 ttyS6_rs485;
    serialConfig configS;
    memset(&configS,0,sizeof(serialConfig));
    configS.baudrate = 115200;
    configS.databits = '8';
    configS.parity = 'N';
    configS.stopbits = '1';

    ret = ttyS6_rs485.openPort( RS485_TTYS_NUM, RTS_IO, &configS);

    key_t key = ftok(msgQueueKeyPath, 0x1234);
    if(key < 0)
    {
        perror("ftok");
        return -1;
    }

    int msg_id = msgget(key, IPC_CREAT);
    if(msg_id < 0)
    {
        perror("msgget");
    }


    ttyS6_rs485.setQueueMsgId(msg_id);
    if(ret<0)
    {
        cout<<"serial ttyS1 open fail"<<endl;
		return -1;
    }

    while(1)
    {
        usleep(200);
    }

}